import json

from django.http import HttpResponse, JsonResponse


def index(request):
    print("index")
    return HttpResponse("hello world")



def queryStringparams(request):
    # 接受字符串传参
    queryDict = request.GET
    a = queryDict.get('a')
    b = queryDict.get('b')
    alist = queryDict.getlist('a')

    print(a)
    print(b)
    print(alist)

    return HttpResponse('queryStringparams')

def routerparams(request,city,year):
    # 接收路由传参
    print(city)
    print(year)

    return HttpResponse('routerparams')


def fromparmas(request):
    # 接收表单传参
    queryDict = request.POST
    a = queryDict.get('a')
    b = queryDict.get('b')
    alist = queryDict.getlist('a')

    print(a)
    print(b)
    print(alist)
    return HttpResponse('fromparmas')


def jsonparams(request):
    # 接收json传参
    dict = json.loads(request.body.decode())

    a = dict.get('a')
    b = dict.get('b')
    print(a)
    print(b)

    # 额外增加的内容:
    # 获取请求头信息:
    length = request.META('CONTENT_LENGTH')
    print(length)

    # 获取请求头中的其他信息
    print(request.method)
    print(request.user)
    print(request.path)

    return HttpResponse('jsonparams')

def responsefunc(request):
    '''接收json传参'''
    print('responsefunc')

    list = [{
        'name': 'zs',
        'age': 123,
        'code': 1000
    }]

    return JsonResponse(list, safe=False)









